﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LaunchySharp;
using System.Diagnostics;
using System.Globalization;
using System.IO;

namespace LingvoTranslate
{
    public class LinvoYandex : IPlugin
    {
        #region IPlugin Members

        private IPluginHost _pluginHost = null;
        private ICatItemFactory _catItemFactory = null;
        private uint _id = 0;
        private string _pluginName = "LingvoYandex";

        public void init(IPluginHost pluginHost)
        {
            _pluginHost = pluginHost;

            if (_pluginHost != null)
            {
                _catItemFactory = _pluginHost.catItemFactory();
                _id = _pluginHost.hash(_pluginName);
            }
        }

        public uint getID()
        {
            return _id;
        }

        public string getName()
        {
            return _pluginName;
        }

        public void getLabels(List<IInputData> inputDataList)
        {
        }

        public void getResults(List<IInputData> inputDataList, List<ICatItem> resultsList)
        {
            if (inputDataList.Count == 1)
            {
                string iconPath = Path.Combine(_pluginHost.launchyPaths().getIconsPath(), "LinvoYandex.ico");
                resultsList.Add(_catItemFactory.createCatItem("translate", "Translate", getID(), iconPath, 0));
            }
        }

        public void getCatalog(List<ICatItem> catalogItems)
        {
        }

        public void launchItem(List<IInputData> inputDataList, ICatItem item)
        {
            string toTranslate = inputDataList[inputDataList.Count - 1].getText();
            string webUrl = string.Format(@"http://lingvo.yandex.ru/en?text={0}&st_translate=on", Uri.EscapeUriString(toTranslate));
            Process.Start(webUrl);
        }

        public bool hasDialog()
        {
            return false;
        }

        public IntPtr doDialog()
        {
            throw new NotSupportedException();
        }

        public void endDialog(bool acceptedByUser)
        {
            throw new NotSupportedException();
        }

        public void launchyShow()
        {
        }

        public void launchyHide()
        {
        }

        #endregion
    }
}
